package zcjq.d829;

import java.util.Arrays;
import java.util.Scanner;

public class DingXiang {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        String str = scanner.nextLine();
        if (n <= 1) {
            System.out.println(0);
        }

        int[] nums = Arrays.stream(str.split(" ")).mapToInt(numStr -> Integer.parseInt(numStr)).toArray();
        int[] orderNums = new int[n];
        int orderNumsLen = 1;
        int result = 0;
        orderNums[0] = nums[0];
        for (int i = 1; i < n; i++) {
            int num = nums[i];
            int idx = bs(orderNumsLen, orderNums, num);
            if (idx > 0) {
                result += idx;
            }
            if (num > orderNums[orderNumsLen - 1]) {
                orderNums[orderNumsLen++] = num;
            }
        }
        System.out.println(result);
    }

    private static int bs(int len, int[] nums, int num) {
        int left = 0, right = len - 1;
        while (left <= right) {
            int mid = (left + right) / 2;
            if (nums[mid] == num) {
                return mid;
            } else if (nums[mid] < num) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        if (left == 0 && nums[left] != num) {
            return -1;
        } else if (right == len - 1 && nums[right] != num) {
            return len;
        }
        return left;
    }
}
